{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "import meanderpy as mp\n",
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "%matplotlib qt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/Users/zoltan/Dropbox/Python\n"
     ]
    }
   ],
   "source": [
    "cd /Users/zoltan/Dropbox/Python"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Input parameters"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 159,
   "metadata": {},
   "outputs": [],
   "source": [
    "W = 200.0                    # channel width (m)\n",
    "D = 12.0                     # channel depth (m)\n",
    "pad = 100                    # padding (number of nodepoints along centerline)\n",
    "deltas = 50.0                # sampling distance along centerline\n",
    "nit = 2000                   # number of iterations\n",
    "Cf = 0.022                    # dimensionless Chezy friction factor\n",
    "crdist = 1.5*W               # threshold distance at which cutoffs occur\n",
    "kl = 60.0/(365*24*60*60.0)   # migration rate constant (m/s)\n",
    "kv =  1.0E-11               # vertical slope-dependent erosion rate constant (m/s)\n",
    "dt = 2*0.05*365*24*60*60.0     # time step (s)\n",
    "dens = 1000                  # density of water (kg/m3)\n",
    "saved_ts = 20                # which time steps will be saved\n",
    "n_bends = 30                 # approximate number of bends you want to model\n",
    "Sl = 0.0                     # initial slope (matters more for submarine channels than rivers)\n",
    "t1 = 500                    # time step when incision starts\n",
    "t2 = 700                    # time step when lateral migration starts\n",
    "t3 = 1400                    # time step when aggradation starts\n",
    "aggr_factor = 4e-9           # aggradation factor (m/s, about 0.18 m/year, it kicks in after t3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Initialize model"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 160,
   "metadata": {},
   "outputs": [],
   "source": [
    "from imp import reload\n",
    "reload(mp)\n",
    "ch = mp.generate_initial_channel(W,D,Sl,deltas,pad,n_bends) # initialize channel\n",
    "chb = mp.ChannelBelt(channels=[ch],cutoffs=[],cl_times=[0.0],cutoff_times=[]) # create channel belt object"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Run simulation"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 161,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "ceeef2fe23e2434f8ebaadef7bf9ab9e",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "FloatProgress(value=1.0, max=1700.0, min=1.0)"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "chb.migrate(nit,saved_ts,deltas,pad,crdist,Cf,kl,kv,dt,dens,t1,t2,t3,aggr_factor) # channel migration\n",
    "fig = chb.plot('strat',20,60) # plotting"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Build 3D fluvial model"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 153,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "56da15fb1c794500a4e6fe9cac4ebf33",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "FloatProgress(value=0.0, max=66.0)"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "h_mud = 0.4 # thickness of overbank deposit for each time step\n",
    "dx = 10.0 # gridcell size in meters\n",
    "\n",
    "chb_3d, xmin, xmax, ymin, ymax = chb.build_3d_model('fluvial',h_mud=h_mud,levee_width=4000.0,h=12.0,w=W,bth=0.0,\n",
    "                            dcr=10.0,dx=dx,delta_s=deltas,starttime=chb.cl_times[20],endtime=chb.cl_times[-1],\n",
    "                            xmin=0,xmax=0,ymin=0,ymax=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 154,
   "metadata": {},
   "outputs": [],
   "source": [
    "# create plots\n",
    "fig1,fig2,fig3 = chb_3d.plot_xsection(200, [[0.5,0.25,0],[0.9,0.9,0],[0.5,0.25,0]], 4)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Build 3D submarine channel model"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 199,
   "metadata": {},
   "outputs": [],
   "source": [
    "W = 200.0                    # channel width (m)\n",
    "D = 12.0                     # channel depth (m)\n",
    "pad = 50                    # padding (number of nodepoints along centerline)\n",
    "deltas = 100.0                # sampling distance along centerline\n",
    "nit = 1500                   # number of iterations\n",
    "Cf = 0.02                    # dimensionless Chezy friction factor\n",
    "crdist = 1.5*W               # threshold distance at which cutoffs occur\n",
    "kl = 60.0/(365*24*60*60.0)   # migration rate constant (m/s)\n",
    "kv =  1.0E-11               # vertical slope-dependent erosion rate constant (m/s)\n",
    "dt = 2*0.05*365*24*60*60.0     # time step (s)\n",
    "dens = 1000                  # density of water (kg/m3)\n",
    "saved_ts = 20                # which time steps will be saved\n",
    "n_bends = 50                 # approximate number of bends you want to model\n",
    "Sl = 0.01                     # initial slope (matters more for submarine channels than rivers)\n",
    "t1 = 500                    # time step when incision starts\n",
    "t2 = 700                    # time step when lateral migration starts\n",
    "t3 = 1000                    # time step when aggradation starts\n",
    "aggr_factor = 4.0          # aggradation factor (it kicks in after t3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 200,
   "metadata": {},
   "outputs": [],
   "source": [
    "reload(mp)\n",
    "ch = mp.generate_initial_channel(W,D,Sl,deltas,pad,n_bends) # initialize channel\n",
    "chb = mp.ChannelBelt(channels=[ch],cutoffs=[],cl_times=[0.0],cutoff_times=[]) # create channel belt object"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 201,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "90129686a3484561ad781d35e79448e5",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "FloatProgress(value=1.0, max=1500.0, min=1.0)"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "chb.migrate(nit,saved_ts,deltas,pad,crdist,Cf,kl,kv,dt,dens,t1,t2,t3,aggr_factor) # channel migration\n",
    "fig = chb.plot('strat',20,60) # plotting"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 213,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "d07889e4d0ce46afa68557d2895ce1f2",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "FloatProgress(value=0.0, max=56.0)"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "h_mud = 3.0*np.ones((len(chb.cl_times[20:]),))\n",
    "dx = 15.0\n",
    "\n",
    "chb_3d, xmin, xmax, ymin, ymax = chb.build_3d_model('submarine',h_mud=h_mud,levee_width=5000.0,h=12.0,w=W,bth=6.0,\n",
    "                            dcr=7.0,dx=dx,delta_s=deltas,starttime=chb.cl_times[20],endtime=chb.cl_times[-1],\n",
    "                            xmin=0,xmax=0,ymin=0,ymax=0)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 214,
   "metadata": {},
   "outputs": [],
   "source": [
    "fig1,fig2,fig3 = chb_3d.plot_xsection(400, [[0.5,0.25,0],[0.9,0.9,0],[0.5,0.25,0]], 10)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
